<?php
/**
 * Created by PhpStorm.
 * User: Tyler
 * Date: 2018/5/2
 * Time: 10:39
 */

namespace App\Http\Controllers;


use App\Logic\SpreadLogic;

class Spread extends Base
{
    /**
     * @api 注册或修改代理人信息
     */
    public function modify()
    {
        SpreadLogic::instance()->checkIdentity($this->param['identity_card']);
        $spreader = SpreadLogic::instance()->newSpread($this->uid);
        $wechat = (isset($this->param['wechat']))?$this->param['wx_id']:'';
        $alipay = (isset($this->param['alipay']))?$this->param['alipay']:'';
        $bank_card = (isset($this->param['bank_card']))?$this->param['bank_card']:'';
        SpreadLogic::instance()->fillSpreaderPayInfo($spreader,$wechat,$alipay,$bank_card);
        SpreadLogic::instance()->fillIdentity($this->uid
            ,$this->param['phone_num']
            ,$this->param['identity_card']
            ,$this->param['realname']);
        $this->returnData();
    }

    //获取代理人信息
    public function spreadinfo()
    {
        SpreadLogic::instance()->spreaderInfo($this->param['uid']);
        $this->returnData();
    }

    //申请套现
    public function kickback()
    {
        SpreadLogic::instance()->applyWithdraw($this->param['uid']
            ,$this->param['num']
            ,$this->param['target']
            ,$this->param['type']
        );
        $this->returnData();
    }

    //查看返点记录
    public function kickbackRec()
    {
        $length = (isset($this->param['length']))?$this->param['length']:10;
        $filter = (isset($this->param['filter']))?$this->param['filter']:0;
        $page = (isset($this->param['page']))?$this->param['page']:1;
        $uid = (isset($this->param['uid']))?$this->param['uid']:0;
        $data = SpreadLogic::instance()->kickbackRecord($this->uid, $uid, $length, $filter, $page);
        return $this->returnData($data);
    }

    //查看套现记录
    public function withdrawRec()
    {
        $length = (isset($this->param['length']))?$this->param['length']:10;
        $filter = (isset($this->param['filter']))?$this->param['filter']:0;
        $page = (isset($this->param['page']))?$this->param['page']:1;
        $data = SpreadLogic::instance()->WithdrawRecord($this->uid, $length, $filter, $page);
        return $this->returnData($data);
    }

    //查看代理人团队信息
    public function teaminfo()
    {
        $length = (isset($this->param['length']))?$this->param['length']:10;
        $filter = (isset($this->param['filter']))?$this->param['filter']:-1;
        $page = (isset($this->param['page']))?$this->param['page']:1;
        $data = SpreadLogic::instance()->spreadTeaminfo($this->uid, $length, $filter, $page);
        return $this->returnData($data);
    }

    //完善用户身份信息
    public function fillIdentityInfo()
    {
        SpreadLogic::instance()->checkIdentity($this->param['identity_card']);
        SpreadLogic::instance()->fillIdentity($this->uid
            ,$this->param['phone_num']
            ,$this->param['identity_card']
            ,$this->param['realname']);
        $this->returnData();
    }
}